//
//  MessageCenterModel.m
//  carcareIOS
//
//  Created by ileo on 16/9/5.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "MessageCenterModel.h"
#import "CalendarMgr.h"
@implementation MessageCenterModel

-(NSObject *)instanceObjectWithProperty:(Property *)property{
    if ([property.name isEqualToString:@"info"]) {
        return [[MessageModel alloc] init];
    }
    return nil;
}

-(void)didValueWithProperty:(Property *)property value:(id)value{
    if ([property.name isEqualToString:@"info"]) {
        NSArray<MessageModel *> *arr = value;
        self.newestMessage = [arr firstObject];
        self.firstID = [arr firstObject].ID;
        self.lastID = [arr lastObject].ID;
    }
}

@end


@implementation MessageModel
- (void)setEXPIRED_DATE:(NSString *)EXPIRED_DATE
{
    _EXPIRED_DATE = EXPIRED_DATE;
    
    NSDate * expiredDate = [CALENDARMGR dateWithStr:EXPIRED_DATE format:@"yyyy-MM-dd HH:mm:ss"];
    NSDate * nowDate = [NSDate date];
    NSComparisonResult result = [expiredDate compare:nowDate];
    _isExpired = (result == NSOrderedAscending);
}
-(void)setCDT:(NSString *)CDT{
    _CDT = CDT;
    
    NSDate *date = [CALENDARMGR dateWithStr:CDT format:@"yyyy-MM-dd HH:mm:ss"];
    
    _dateTime = ([CalendarMgr isTodayWithDate:date] ? @"今天" : (([[CALENDARMGR dateStrWithDate:[CALENDARMGR dateWithStr:CDT format:@"yyyy-MM-dd HH:mm:ss"] format:@"yyyy-MM-dd"] isEqualToString:[CALENDARMGR beforeDay]]) ? @"昨天" : [CALENDARMGR dateStrWithDate:date format:@"yyyy-MM-dd"]));
    _carMessageTime = [CALENDARMGR dateStrWithDate:date format:@"HH:mm:ss"];
    _messageTimeDate = [NSString stringWithFormat:@"%@ %@",_dateTime,[CALENDARMGR dateStrWithDate:date format:@"HH:mm"]];

}

@end

